import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;


public class Particle {
ydPoint position;
ydPoint velocity;

int originalLife;
int life;
double ageRatio;

int originalSize;
int size;

Image img;

Color color;

float[] startColor={235f, 166f, 255f, 1f};
float[] endColor={89f,23f,255f,0f};
float[] deltaColor={0,0,0,0};

public Particle(){
	position=new ydPoint();
	velocity=new ydPoint();
	
	this.originalLife=0;
	this.life=0;
	
	this.originalSize=0;
	this.size=0;
	
	color=Color.BLUE;
}

public Particle(ydPoint p, ydPoint v, int life, int size){
	position=new ydPoint(p);
	velocity=new ydPoint(v);
	
	this.originalLife=life;
	this.life=life;
	
	this.originalSize=size;
	this.size=size;
	
	color=Color.BLUE;
	
	deltaColor[0]=(endColor[0]-startColor[0])/life;
	deltaColor[1]=(endColor[1]-startColor[1])/life;
	deltaColor[2]=(endColor[2]-startColor[2])/life;
	deltaColor[3]=(endColor[3]-startColor[3])/life;
	
	img=Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("res/particleTexture2.png"));
}

public void update(){
	ageRatio=(double)life/originalLife;
	if(life>0){
		nextPosition();
		nextSize();
		nextColor();
	}
	life--;
}

public void nextPosition(){
	position.x+=velocity.x;
	position.y+=velocity.y;
}

public void nextSize(){
	size=(int) (originalSize*ageRatio);
	return;
}

public void nextColor(){
	startColor[0]+=deltaColor[0];
	startColor[1]+=deltaColor[1];
	startColor[2]+=deltaColor[2];
	startColor[3]+=deltaColor[3];
	
	color=new Color(startColor[0]/255, startColor[1]/255, startColor[2]/255, startColor[3]);
}

public void draw(Graphics g){
	//g.drawArc;
	if(life>0){
		//g.setColor(new Color(255,100,200,(int) (255*ageRatio)));
		
		
		g.setColor(color);
	//	g.drawImage(img, (int)position.x, (int)position.y, size, size, color, null);
		g.fillArc((int)position.x, (int)position.y, size, size, 0, 360);
}
}

}
